class Solution:
    def isHappy(self, n: int) -> bool:
        flag = dict()
        check = False
        while True:
            num = str(n)
            temp = 0
            if n in flag and check:
                return False
            elif n in flag:
                check = True
            else:
                check = False

            for it in num:
                temp += int(it) * int(it)
            flag[n] = temp
            n = temp

            if n == 1:
                return True